package com.rabbitmq.demo.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.demo.conf.WorkQueueConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * 工作模式消费者1
 *
 * @Author yi.cheng
 * @Date 2023-7-12 14:19
 **/
@Slf4j
@Component
public class WorkQueueConsumer1 {
    @RabbitListener(queues = WorkQueueConfig.WORK_QUEUE_NAME)
    public void getWorkQueueMessage(Message message, Channel c, Map msg) throws IOException {
        MessageProperties properties = message.getMessageProperties();
        long tag = properties.getDeliveryTag();
        log.info("工作模式消费者1 消费了：{}",msg);
        // 手动回执，不批量签收,回执后才能处理下一批消息
        c.basicAck(tag,false);
    }
}
